package com.base.cn.platform.os.controller.qa.record;

import com.base.cn.platform.os.common.controller.BaseController;
import com.base.cn.platform.os.common.mybatis.Pagination;
import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.entity.qa.question.QaQuestion;
import com.base.cn.platform.os.entity.qa.record.QaGainAttendRecord;
import com.base.cn.platform.os.service.qa.question.QaQuestionBiz;
import com.base.cn.platform.os.service.qa.record.QaGainAttendRecordBiz;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Map;


/**
 * 围观收益记录Controller
 * @author LIZHIPENG
 * @since 2018/5/2
 */
@RestController
@RequestMapping("/course")
public class QaGainAttendRecordController extends BaseController {

    @Autowired
    private QaGainAttendRecordBiz gainAttendRecordBiz;
    @Autowired
    private QaQuestionBiz  qaQuestionBiz;

    /**
     * 查询旁听分成收益数量
     * @param gainAttendRecord 查询条件
     * @return 数量
     */
    @RequestMapping("/getGainAttenRecordCount")
    public BigDecimal getGainAttenRecordCount(@RequestBody QaGainAttendRecord gainAttendRecord){
        return gainAttendRecordBiz.getGainAttenRecordCount(gainAttendRecord);
    }

    /**
     * 分页查询旁听收益记录
     * @param currentPage 页码
     * @param gainAttendRecord 条件
     * @param questionData 是否设置问题数据：true：是，false:否
     * @param userData 是否设置用户数据：true：是，false:否
     * @return
     */
    @RequestMapping("/queryGainAttendRecordListPage")
    public PageInfo<QaGainAttendRecord> queryGainAttendRecordListPage(@RequestParam(value = "currentPage", required = false, defaultValue = "1")int currentPage,
                                                                      @RequestBody QaGainAttendRecord gainAttendRecord,
                                                                      @RequestParam("questionData")boolean questionData,
                                                                      @RequestParam("userData")boolean userData){
        Pagination page = new Pagination();
        page.setCurrentPage(currentPage);
        return gainAttendRecordBiz.queryGainAttendRecordListPage(page, gainAttendRecord, questionData, userData);
    }

    /**
     * 查询用户问答收益总额
     * @param qaGainAttendRecord 查询条件
     * @return double总收益
     */
    @RequestMapping("/getUserQaEarning")
    public double getUserQaEarning(@RequestBody QaGainAttendRecord qaGainAttendRecord){
        return gainAttendRecordBiz.getUserQaEarning(qaGainAttendRecord);
    }

    /**
     * 提取收益到我的账户
     * @param qaGainAttendRecord 提取条件
     * @return Map<String, Object>
     */
    @RequestMapping("/extractEarning")
    public Map<String, Object> extractEarning(@RequestBody QaGainAttendRecord qaGainAttendRecord){
        qaGainAttendRecord.setStatus(1);//查询未提取的记录
        String message = gainAttendRecordBiz.extractEarning(qaGainAttendRecord);
        return ResultUtil.SUCCESS(message);
    }

    /**
     * 分页查询旁听收益记录
     * @param currentPage 页码
     * @param gainAttendRecord 条件
     * @return
     */
    @RequestMapping("/queryAdminGainAttendRecordListPage")
    public PageInfo<QaQuestion> queryAdminGainAttendRecordListPage(@RequestParam(value = "currentPage", required = false, defaultValue = "1")int currentPage,
                                                                      @RequestBody QaGainAttendRecord gainAttendRecord){
        Pagination page = new Pagination();
        page.setCurrentPage(currentPage);
        page.setPageSize(12);

        return gainAttendRecordBiz.queryAdminGainAttendRecordListPage(page, gainAttendRecord);
    }

}
